﻿package mortal.game.view.warehouse.panel
{
    import Message.Game.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.manager.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.pack.data.*;
    import mortal.game.view.pack.social.*;
    import mortal.mvc.core.*;

    public class WarehouseItem extends BaseItem
    {
        private var _notMeetCareerEffect:ScaleBitmap;
        private var _isNotMeet:Boolean;
        private var _data:Object;

        public function WarehouseItem()
        {
            return;
        }// end function

        override protected function updateView() : void
        {
            if (canNotUseEffect)
            {
                canNotUseEffect.width = _width - _paddingLeft * 2;
                canNotUseEffect.height = _height - _paddingTop * 2;
                canNotUseEffect.x = _paddingLeft;
                canNotUseEffect.y = _paddingTop;
            }
            if (lockedIcon)
            {
                lockedIcon.x = _paddingLeft;
                lockedIcon.y = _paddingTop;
            }
            if (_amountLabel)
            {
                _amountLabel.width = _width - _paddingLeft * 2;
                _amountLabel.x = _paddingLeft;
                _amountLabel.y = _height - _paddingTop - _amountLabel.height;
            }
            if (this._notMeetCareerEffect)
            {
                this._notMeetCareerEffect.width = _width - _paddingLeft * 2;
                this._notMeetCareerEffect.height = _height - _paddingTop * 2;
                this._notMeetCareerEffect.x = _paddingLeft;
                this._notMeetCareerEffect.y = _paddingTop;
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            isShowLock = true;
            this.mouseEnabled = true;
            this.mouseChildren = false;
            this._isCheckOtherSkillBookState = true;
            this.configEventListener(MouseEvent.CLICK, this.moveToPack);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._notMeetCareerEffect)
            {
                this._notMeetCareerEffect.dispose(param1);
                this._notMeetCareerEffect = null;
            }
            _itemData = null;
            this._data = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function moveToPack(event:MouseEvent) : void
        {
            var _loc_2:Object = null;
            if (itemData && itemData.itemInfo)
            {
                if (Cache.instance.pack.backPackCache.isPackFull(itemData.itemCode, itemData.serverData.itemAmount))
                {
                    return MsgManager.showRollTipsMsg(Language.getString(35524), MsgRollTipsType.msgRollTips3);
                }
                _loc_2 = new Object();
                _loc_2.pos = EMoveType._EMoveTypeToBag;
                _loc_2.item = this.itemData;
                Dispatcher.dispatchEvent(new DataEvent(EventName.WarehouseToPack, _loc_2));
            }
            else if (itemData == PackItemData.lockItemData)
            {
                ItemFeatureTips.openWarehouseGrid(this.pos, this._data);
            }
            return;
        }// end function

        public function set isNotMeetCarrer(param1:Boolean) : void
        {
            this._isNotMeet = param1;
            if (this._isNotMeet)
            {
                if (!this._notMeetCareerEffect)
                {
                    this._notMeetCareerEffect = ResourceConst.getScaleBitmap(ImagesConst.PackDisable);
                    _middleLayer.addChild(this._notMeetCareerEffect);
                    this._notMeetCareerEffect.width = _width - _paddingLeft * 2;
                    this._notMeetCareerEffect.height = _height - _paddingTop * 2;
                    this._notMeetCareerEffect.x = _paddingLeft;
                    this._notMeetCareerEffect.y = _paddingTop;
                }
            }
            if (this._notMeetCareerEffect)
            {
                this._notMeetCareerEffect.visible = this._isNotMeet;
                if (GameController.trade.isViewShow)
                {
                    this._notMeetCareerEffect.visible = false;
                }
            }
            return;
        }// end function

        override public function set itemData(param1:ItemData) : void
        {
            if (itemData == param1)
            {
                return;
            }
            this.isDragAble = false;
            this.isDropAble = false;
            this.isNotMeetCarrer = false;
            this.isBind = false;
            this.isPrescritime = false;
            this.amount = 0;
            this.removeEventListener(MouseEvent.ROLL_OVER, this.showUnLockIcon);
            this.removeEventListener(MouseEvent.ROLL_OUT, this.hideUnLockIcon);
            if (param1 == PackItemData.lockItemData)
            {
                this.source = GlobalClass.getBitmap(ImagesConst.WarehouseLock);
                this.amount = 0;
                _itemData = param1;
                isBind = false;
                this.buttonMode = true;
                this.configEventListener(MouseEvent.ROLL_OVER, this.showUnLockIcon);
                this.configEventListener(MouseEvent.ROLL_OUT, this.hideUnLockIcon);
            }
            else if (param1)
            {
                _itemData = param1;
                this.source = param1.itemInfo.url;
                this.amount = param1.serverData.itemAmount;
                this.isShowToolTip = true;
                this.buttonMode = true;
                this.isDragAble = true;
                this.isDropAble = true;
                this.isNotMeetCarrer = !ItemsUtil.isFitCarrer(itemData);
                this.isBind = ItemsUtil.isBind(this.itemData);
                this.isPrescritime = ItemsUtil.isPrescriptionItem(param1);
            }
            else
            {
                _itemData = null;
                this.source = null;
                this.amount = 0;
                this.isBind = false;
                this.isDropAble = true;
                this.buttonMode = false;
            }
            updateColorShow();
            updateStrengLevel();
            updateAroundEffect();
            checkMountSkillBookState();
            return;
        }// end function

        private function showUnLockIcon(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WarehouseShowUnLock, this.pos));
            return;
        }// end function

        private function hideUnLockIcon(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WarehouseShowUnLock, null));
            return;
        }// end function

        override protected function onMouseDown(event:MouseEvent) : void
        {
            if (this.itemData && this.isDragAble && !_cannotUse)
            {
                DragManager.instance.startDragItem(this, bitmapdata);
            }
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            if (this._data == param1)
            {
                return;
            }
            this._data = param1;
            return;
        }// end function

        override public function get toolTipData()
        {
            if (itemData == PackItemData.lockItemData || itemData == PackItemData.unLockingItemData)
            {
                return Language.getString(30050);
            }
            if (itemData == PackItemData.unLockItemData)
            {
                return Language.getString(30051);
            }
            if (itemData)
            {
                return itemData;
            }
            return super.toolTipData;
        }// end function

    }
}
